package com.feather.unit;

import java.util.Map;

import com.feather.annotation.ActionMethod;
import com.feather.annotation.InputParam;

public class MapActionUnit {
	@ActionMethod
	public String mapGetString(
			@InputParam(name="map") Map<String, Object> map,
			@InputParam(name="key") String key)
	{
		Object value = map.get(key);
		if(value == null)
			return null;
		
		if(value instanceof String)
			return (String) value;
		
		return value.toString();
	}
	
	@ActionMethod
	public Long mapGetLong(
			@InputParam(name="map") Map<String, Object> map,
			@InputParam(name="key") String key
			)
	{
		Object value = map.get(key);
		if(value == null)
			return null;
		
		if(value instanceof Number)
			return ((Number)value).longValue();
		
		if(value instanceof String)
			return Long.parseLong((String)value);
		
		return null;
	}
}
